package test1;

import static org.lwjgl.opengl.GL11.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.lwjgl.opengl.*;
import org.lwjgl.*;
import org.newdawn.slick.opengl.*;

public class TextureDemo
{
	/*********************************** BEGIN CONSTANTS *******************************************/
	public static final int WIDTH = 800;
	public static final int HEIGHT = 600;
	public static final int ZNEAR = 1;

	/*********************************** END CONSTANTS *******************************************/

	private Texture wood;
	public TextureDemo()
	{
		try
		{
			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
			Display.setTitle("Hello, LWJGL!");
			Display.create();
		} catch (LWJGLException e)
		{
			e.printStackTrace();
		}
		
		wood = loadTexture("wood");
		
		// Initialize OpenGL
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, WIDTH, HEIGHT, 0, ZNEAR, -1);
		glMatrixMode(GL_MODELVIEW);
		glEnable(GL_TEXTURE_2D);

		while (!Display.isCloseRequested())
		{
			glClear(GL_COLOR_BUFFER_BIT);
			
			wood.bind();
			
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(400,400);
			glTexCoord2f(1,0);
			glVertex2i(500,400);
			glTexCoord2f(1, 1);
			glVertex2i(500,500);
			glTexCoord2f(0, 1);
			glVertex2i(400,500);
			glEnd();		

			Display.update();
			Display.sync(60);
		}
		Display.destroy();
	}
	
	private Texture loadTexture(String key)
	{
		try
		{
			return TextureLoader.getTexture("PNG", new FileInputStream(new File("res/" + key + ".png")));
		} catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block			
			e.printStackTrace();
		} catch (IOException e)
		{
			System.out.println("here");
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}

	public static void main(String[] args)
	{
		new TextureDemo();

	}

}
